package com.waters321.rock.web.tool;

import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.waters321.rock.orm.dao.generator.frame.FrameDemoDao;
import com.waters321.rock.orm.entity.frame.FrameDemo;

@RestController
@RequestMapping("/id")
public class SequenceController {
  @Autowired
  private FrameDemoDao frameDemoDao;

  @RequestMapping(method = {RequestMethod.POST, RequestMethod.GET})
  public Object test(HttpServletRequest request, HttpServletResponse response) {

    FrameDemo insert = new FrameDemo();
    insert.setName("名字" + new Random().nextInt(1000));
    frameDemoDao.insert(insert);
    Assert.assertNotNull(insert.getId());

    FrameDemo one = frameDemoDao.selectById(insert.getId());
    Assert.assertNotNull(one);

    FrameDemo update = new FrameDemo();
    update.setId(insert.getId());
    update.setName("名字" + 333);
    frameDemoDao.updateById(update);
    one = frameDemoDao.selectById(insert.getId());
    Assert.assertEquals(one.getName(), "名字" + 333);

    List<FrameDemo> all = frameDemoDao.selectList(new EntityWrapper<FrameDemo>());
    Assert.assertTrue(all.size() > 0);

    FrameDemo frameDemoDelete = new FrameDemo();
    frameDemoDelete.setId(insert.getId());
    frameDemoDelete.deleteById();
    one = frameDemoDao.selectById(insert.getId());
    Assert.assertNull(one);

    return "ok";

  }
}
